package com.mdd.front.controller;

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.IShopAppRecordService;
import com.mdd.front.validate.ShopAppRecordCreateValidate;
import com.mdd.front.validate.ShopAppRecordSearchValidate;
import com.mdd.front.validate.common.PageValidate;
import com.mdd.front.vo.record.ShopRecordDetailVo;
import com.mdd.front.vo.record.ShopRecordListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/shop/record")
@Api(tags = "开店申请管理")
public class ShopAppRecordController {
    @Resource
    private IShopAppRecordService iShopAppRecordService;

    @PostMapping("/add")
    @ApiOperation(value="开店申请新增")
    public AjaxResult<Object> add(@Validated @RequestBody ShopAppRecordCreateValidate createValidate) {
        Integer userId = LikeFrontThreadLocal.getUserId();
        createValidate.setUserId(userId);
        iShopAppRecordService.add(createValidate);
        return AjaxResult.success();
    }

    @GetMapping("/list")
    @ApiOperation(value="开店申请列表")
    public AjaxResult<PageResult<ShopRecordListedVo>> list(@Validated PageValidate pageValidate,
                                                           @Validated ShopAppRecordSearchValidate searchValidate) {
        Integer userId = LikeFrontThreadLocal.getUserId();
        PageResult<ShopRecordListedVo> list = iShopAppRecordService.list(pageValidate, userId);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="开店申请详情")
    public AjaxResult<ShopRecordDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ShopRecordDetailVo detail = iShopAppRecordService.detail(id);
        return AjaxResult.success(detail);
    }

    @NotLogin
    @GetMapping("/sendCode")
    @ApiOperation(value="发送短信")
    public AjaxResult<Object> sendCode(String mobile) {
        Assert.notNull(mobile, "请输入手机号码");
    	return iShopAppRecordService.sendCode(mobile);
    }

}
